package edu.biwu.response;

import jakarta.servlet.*;
import jakarta.servlet.http.*;
import jakarta.servlet.annotation.*;

import java.io.IOException;

/**
 * HttpServletResponse操作字符流中文：
 *    public String getCharacterEncoding():获取字符输出流中默认使用的码表
 * 浏览器乱码的产生：
 *    1.response.getWriter().write("你好")=>将“你好”进行查询UTF-8表（一个弘文3个字节）
 *    2.浏览器默认使用系统码表(GBK)=>浏览器会将E4 BD E5 A5 BD查询GBK码表（一个中文2个字节）=>浣犲ソ
 */
@WebServlet("/resp/demo04")
public class ResponseDemo04 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        /*System.out.println(response.getCharacterEncoding());*/
        response.setContentType("text/html;charset=utf-8");
        response.getWriter().write("你好");
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }
}
